CC =		gcc
CXX =		g++

CFLAGS =	-g -Wall -W -I. -DDEBUG
LDFLAGS =	-g
# CYGWIN32 users may need to add the -luser32 flag to GUILDFLAGS.
# Non-development public releases of executables should be linked
# with the -mwindows flag.
# During debugging (i.e. -DDEBUG enabled) you should not link
# with the -mwindows flags, otherwise you will loose all the debugging messages.
GUILDFLAGS = # -luser32 -mwindows

# The console version contains only the non-GUI classes, like QString and QObject
LIBCONSOLE =	libminiqtc.a
# the GUI library contains the console classes plus the GUI classes
LIBGUI =	libminiqt.a

LIBCONSOLEOBJS =qmisc.o qstring.o qobject.o
LIBGUIOBJS =	$(LIBCONSOLEOBJS) \
		qstartup.o qevent.o qapplication.o qwidget.o qpushbutton.o \
		moc_qapplication.o moc_qpushbutton.o
MINIMOC =	./minimoc.exe
EXAMPLES =	example_c1.exe example_c2.exe example_c3.exe \
		example_g1.exe example_g2.exe

.SUFFIXES: .cpp

.c.o:
	$(CC) -c $(CFLAGS) $<

.cpp.o:
	$(CXX) -c $(CFLAGS) $<

all: $(MINIMOC) $(LIBCONSOLE) $(LIBGUI) $(EXAMPLES)

#
# Mini Meta Object Compiler
#

$(MINIMOC): minimoc.o
	$(CC) -o $(MINIMOC) minimoc.o

#
# Libraries
#

$(LIBCONSOLE): $(LIBCONSOLEOBJS)
	rm -f $(LIBCONSOLE)
	ar rcs $(LIBCONSOLE) $(LIBCONSOLEOBJS)

$(LIBGUI): $(LIBGUIOBJS)
	rm -f $(LIBGUI)
	ar rcs $(LIBGUI) $(LIBGUIOBJS)

moc_qapplication.cpp: $(MINIMOC) qapplication.h
	$(MINIMOC) qapplication.h moc_qapplication.cpp

moc_qpushbutton.cpp: $(MINIMOC) qpushbutton.h
	$(MINIMOC) qpushbutton.h moc_qpushbutton.cpp

#
# Examples
#

example_c1.exe: example_c1.o $(LIBCONSOLE)
	$(CXX) -o example_c1.exe example_c1.o $(LDFLAGS) $(LIBCONSOLE)

example_c2.exe: example_c2.o $(LIBCONSOLE)
	$(CXX) -o example_c2.exe example_c2.o $(LDFLAGS) $(LIBCONSOLE)

example_c3.exe: example_c3.o moc_example_c3.o $(LIBCONSOLE)
	$(CXX) -o example_c3.exe example_c3.o moc_example_c3.o $(LDFLAGS) $(LIBCONSOLE)

moc_example_c3.cpp: $(MINIMOC) example_c3.h
	$(MINIMOC) example_c3.h moc_example_c3.cpp

example_g1.exe: example_g1.o $(LIBGUI)
	$(CXX) -o example_g1.exe example_g1.o $(LDFLAGS) $(LIBGUI) $(GUILDFLAGS)

example_g2.exe: example_g2.o moc_example_g2.o $(LIBGUI)
	$(CXX) -o example_g2.exe example_g2.o moc_example_g2.o $(LDFLAGS) $(LIBGUI) $(GUILDFLAGS)

moc_example_g2.cpp: $(MINIMOC) example_g2.h
	$(MINIMOC) example_g2.h moc_example_g2.cpp

clean:
	rm -f *.exe *.o *.a moc_*.cpp *.~*

deps:
	$(CXX) -MM *.cpp >Makefile.deps

include Makefile.deps
